/**
 * BigCharFactory.java
 *
 * Provider: CoderDream's Studio
 *
 * History
 *	Date(DD/MM/YYYY)    Author          Description
 * ----------------------------------------------------------------------------
 *	Oct 31, 2007		CoderDream		Created
 */
package com.coderdream.chapter20.flyweight.sample;

import java.util.Hashtable;

/**
 * <pre>
 * BigCharFactory.java
 * </pre>
 * 
 */
public class BigCharFactory {
	// 管理现有的BigChar对象实例
	private Hashtable pool = new Hashtable();
	// Singletom Pattern
	private static BigCharFactory singleton = new BigCharFactory();

	/**
	 * 私有构造函数
	 */
	private BigCharFactory() {
	}

	/**
	 * 取得唯一的对象实例
	 * 
	 * @return
	 */
	public static BigCharFactory getInstance() {
		return singleton;
	}

	public synchronized BigChar getBigChar(char charname) {
		BigChar bc = (BigChar) pool.get("" + charname);
		if (bc == null) {
			bc = new BigChar(charname);// 在此产生BigChar的对象实例
			pool.put("" + charname, bc);
		}

		return bc;
	}

}
